package code.BinaryTree;

import struct.Tree;
import struct.TreeNode;

import java.util.HashMap;
import java.util.HashSet;

public class FindElements {
	HashMap<Integer, Integer> hashMap = new HashMap<>();

	public static void main(String[] args) {
		TreeNode tree = Tree.constructTree("[-1,-1,-1,-1,-1]");
		FindElements findElements = new FindElements(tree);
		boolean one = findElements.find(6);
		System.out.println(one);
	}

	public FindElements(TreeNode root) {
		if (root == null) {
			return;
		}
		FindElementsHlper(root, 0);
	}

	public void FindElementsHlper(TreeNode root, int val) {
		if (root == null) {
			return;
		}
		root.val = val;
		hashMap.put(root.val,0);
		FindElementsHlper(root.left, 2 * root.val + 1);
		FindElementsHlper(root.right, 2 * root.val + 2);
	}

	public boolean find(int target) {
		return hashMap.containsKey(target);
	}
}
